from django.template import Library
from web import models
from django.urls import reverse

register = Library()


@register.inclusion_tag('web/inclusion/all_project_list.html')
def all_project_list(request):
    """ 给所有的模板提供所有项目列表 """
    create_project_list = models.Project.objects.filter(creator=request.login_user.user)

    join_project_list = models.ProjectUser.objects.filter(user=request.login_user.user)

    return {'create': create_project_list, 'join': join_project_list, 'request': request}


@register.inclusion_tag('web/inclusion/manage_project_list.html')
def manage_project_list(request):
    """ 项目管理页面菜单 """
    menu_list = [
        {'title': '概览', 'url': reverse('dashboard', kwargs={'project_id': request.login_user.project.id})},
        {'title': 'wiki', 'url': reverse('wiki', kwargs={'project_id': request.login_user.project.id})},
        {'title': '文件', 'url': reverse('file', kwargs={'project_id': request.login_user.project.id})},
        {'title': '工单', 'url': reverse('issues', kwargs={'project_id': request.login_user.project.id})},
        #{'title': '统计', 'url': reverse('statistic', kwargs={'project_id': request.login_user.project.id})},
        {'title': '配置', 'url': reverse('setting', kwargs={'project_id': request.login_user.project.id})},
    ]
    for menu in menu_list:
        if request.path_info.startswith(menu['url']):
            menu['class'] = 'active'
    return {'menu_list': menu_list, 'request': request}
